package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.OperationRemind;
import com.ruoyi.business.service.IOperationRemindService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 综合消息提醒Controller
 * 
 * @author ruoyi
 * @date 2022-04-16
 */
@RestController
@RequestMapping("/business/operation_remind")
public class OperationRemindController extends BaseController
{
    @Autowired
    private IOperationRemindService operationRemindService;

    /**
     * 查询综合消息提醒列表
     */
    @PreAuthorize("@ss.hasPermi('business:operation_remind:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperationRemind operationRemind)
    {
        startPage();
        List<OperationRemind> list = operationRemindService.selectOperationRemindList(operationRemind);
        return getDataTable(list);
    }

    /**
     * 导出综合消息提醒列表
     */
    @PreAuthorize("@ss.hasPermi('business:operation_remind:export')")
    @Log(title = "综合消息提醒", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OperationRemind operationRemind)
    {
        List<OperationRemind> list = operationRemindService.selectOperationRemindList(operationRemind);
        ExcelUtil<OperationRemind> util = new ExcelUtil<OperationRemind>(OperationRemind.class);
        return util.exportExcel(list, "综合消息提醒数据");
    }

    /**
     * 获取综合消息提醒详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:operation_remind:query')")
    @GetMapping(value = "/{remindId}")
    public AjaxResult getInfo(@PathVariable("remindId") Long remindId)
    {
        return AjaxResult.success(operationRemindService.selectOperationRemindByRemindId(remindId));
    }

    /**
     * 新增综合消息提醒
     */
    @PreAuthorize("@ss.hasPermi('business:operation_remind:add')")
    @Log(title = "综合消息提醒", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationRemind operationRemind)
    {
        return toAjax(operationRemindService.insertOperationRemind(operationRemind));
    }

    /**
     * 修改综合消息提醒
     */
    @PreAuthorize("@ss.hasPermi('business:operation_remind:edit')")
    @Log(title = "综合消息提醒", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationRemind operationRemind)
    {
        return toAjax(operationRemindService.updateOperationRemind(operationRemind));
    }

    /**
     * 删除综合消息提醒
     */
    @PreAuthorize("@ss.hasPermi('business:operation_remind:remove')")
    @Log(title = "综合消息提醒", businessType = BusinessType.DELETE)
	@DeleteMapping("/{remindIds}")
    public AjaxResult remove(@PathVariable Long[] remindIds)
    {
        return toAjax(operationRemindService.deleteOperationRemindByRemindIds(remindIds));
    }

    @GetMapping("/updateStatus/{businessId}/{remindType}/{userId}")
    public AjaxResult updateStatus(@PathVariable String businessId, @PathVariable String remindType, @PathVariable String userId) {
        OperationRemind operationRemind = new OperationRemind();
        operationRemind.setOperationType(remindType);
        operationRemind.setBusinessId(Long.valueOf(businessId));
        operationRemind.setUserId(Long.valueOf(userId));
        List<OperationRemind> operationReminds = operationRemindService.selectOperationRemindList(operationRemind);
        for (OperationRemind item : operationReminds) {
            item.setIsComplete("1");
            operationRemindService.updateOperationRemind(item);
        }
        return toAjax(operationReminds.size());
    }
}
